home *** CD-ROM | disk | FTP | other *** search
- Path: longwood.cs.ucf.edu!not-for-mail
- From: stevens@longwood.cs.ucf.edu (John Stevens)
- Newsgroups: comp.lang.c++
- Subject: Re: Why use private class members instead of protected?
- Date: 22 Jan 1996 10:16:52 -0500
- Organization: University of Central Florida
- Message-ID: <4e09p4$sku@longwood.cs.ucf.edu>
- References: <30F4AB49.6ABB@sierra.net>
- NNTP-Posting-Host: longwood.cs.ucf.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- TGColwell (snowbull@sierra.net) wrote:
- : I'm relatively new to c++. I have one quick question: If child
- : classes can only access protected members of the parent class,
- : why make any members of any class private? Wouldn't it be
- : better to make members of the parent class protected so that the
- : class is alway "inheritance ready"?
-
- The short answer is that you may wish to encapsulate the implementation
- of your base class from your children, and enforce the derived classes
- use of access methods, etc. This is a design tradeoff (as usual) but
- consider what happens if I muck about with the protected internals of
- a base class in a dozen derived classes (even unto the 2nd and 3rd
- generations). Now I want to change the implementation of the base class.
- In the words of the immortal Astro: "Ruh-roh!". This is more common (at
- least in my commercial experience) than you might think, and it will
- burn you.
-
- Any other comments?
-
- My $.02.
- John S.
-
-